package com.dgut.staffmodule.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.dgut.staffmodule.entity.Department;
import com.dgut.staffmodule.entity.Position;

@Repository
public interface PositionRepository
		extends PagingAndSortingRepository<Position, Long>, JpaSpecificationExecutor<Position> {
	// 查找指定部门下的所有职位
	@Query(value = "select * from t_position where department_id =:id", nativeQuery = true)
	public List<Position> findAllByDeptId(@Param("id") Long id);

	// 通过职位名称查找该职位
	@Query(value = "select * from t_position where positionName = :positionName", nativeQuery = true)
	public Position findByPosName(@Param("positionName") String positionName);

	// 根据部门ID和职称找部门领导
	@Query(value = "select * from t_position where department_id =:id and positionName like '%总监%'", nativeQuery = true)
	public Department findDepartmentLeader(@Param("id") Long id);
}
